import './assets/main.css'

import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import axios from 'axios'
import Video from 'video.js'
import 'video.js/dist/video-js.css'

// 引入echarts
import Echarts from 'vue-echarts'
import * as echarts from 'echarts'


// axios.defaults.baseURL="http://localhost:8080"
axios.defaults.baseURL="http://47.97.33.39:8080"
//加入拦截器
axios.interceptors.request.use(config=>{
  //获取token
  const token=localStorage.getItem("token");
  console.log(token)
  //判断token是否存在
  if(token){
    config.headers.token=token
  }
  return config;
})

axios.interceptors.response.use(res=>{
  if(res.data.code==401){
    router.push("/")
  } else{
    return res;
  }
})

const app = createApp(App)
app.component('e-charts', Echarts)
app.config.globalProperties.$video = Video
app.use(router)
app.use(ElementPlus)
app.mount('#app')
app.use(axios)
app.component('e-charts', Echarts)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
  }
